#include "ShaderTexture.h"
#include "Renderer.h"

CShaderTexture::CShaderTexture(const char* szShaderName, int nUsage) :
	CShaderBase(szShaderName, nUsage)
{
}

CShaderTexture::~CShaderTexture(void)
{
}

void CShaderTexture::CreateParameterHandle(TMaterial& tMaterial, unsigned int nShaderIndex)
{
	// Get our effect from the renderer
	ID3DXEffect* effect = CRenderer::GetInstance()->GetEffectFromBank(nShaderIndex);

	// Begin parameter block
	effect->BeginParameterBlock();
	{
		// Apply each parameter
		if(tMaterial.m_nDiffuseID != -1)
		{
			effect->SetTexture("gDiffuseTexture", CRenderer::GetInstance()->GetTextureFromBank(tMaterial.m_nDiffuseID));
		}
		if(tMaterial.m_nEmissiveID != -1)
		{
		effect->SetTexture("gEmissiveTexture", CRenderer::GetInstance()->GetTextureFromBank(tMaterial.m_nEmissiveID));
		}
		if(tMaterial.m_nSpecularID != -1)
		{
		effect->SetTexture("gSpecularTexture", CRenderer::GetInstance()->GetTextureFromBank(tMaterial.m_nSpecularID));
		}
		if(tMaterial.m_nNormalID != -1)
		{
		effect->SetTexture("gNormalTexture", CRenderer::GetInstance()->GetTextureFromBank(tMaterial.m_nNormalID));
		}

	} // End our parameter block
	tMaterial.m_hParameters = effect->EndParameterBlock();
}